#pragma once

#include "InvocationAction.h"

#include "InputPin.h"
#include "Port.h"

namespace uml {

InvocationAction::InvocationAction(const QString& umlType)
    : Action(umlType) {}

void InvocationAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(arguments_, "arguments", json, errorList);
    onPort_ = JsonSerializable::create<Port>(json.value("onPort"), errorList);

}

void InvocationAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    JsonSerializable::toJsonArray(arguments_, "arguments", json);
    if (onPort_) {
        QJsonObject onPort_json;
        onPort_->toJson(onPort_json);
        json.insert("onPort", onPort_json);
    }
}

/// <summary>
/// arguments getter
/// The InputPins that provide the argument values passed in the invocation request.
/// </summary>
vector<shared_ptr<InputPin>>& InvocationAction::arguments() {
    return arguments_;
}

/// <summary>
/// onPort getter
/// For CallOperationActions, SendSignalActions, and SendObjectActions, an optional
/// Port of the target object through which the invocation request is sent.
/// </summary>
shared_ptr<Port> InvocationAction::onPort() const {
    return onPort_;
}

/// <summary>
/// onPort setter
/// For CallOperationActions, SendSignalActions, and SendObjectActions, an optional
/// Port of the target object through which the invocation request is sent.
/// </summary>
void InvocationAction::setOnPort(shared_ptr<Port> value) {
    onPort_ = value;
}

} // namespace uml
